import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, DelDataButton, AnnexButton } from '../Common/options'

export const PlanStatAttachment = async ({ OptionsEvent, oneData, Permission }) => {
    let dataList = {
        type: '计量附件列表',
        hideInSearch: true,
        pageSize: 10,
        params: { OrderField: 'createTime@desc', planStatUuid: oneData.uuid },
        initialValues: { planStatUuid: oneData.uuid },
        get: API_LIST([oneData.uuid])['getPlanStatAttachment'],
        added: 'posPlanStatAttachment',
        options: [
            Permission.findIndex(v => v.uuid === '4aaf53ba-42a7-4349-b56c-476be223346a') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="添加附件" />
            ),
        ],
        columns: [
            {
                dataIndex: 'planStatUuid',
                title: 'planStatUuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            { ...commonTableList.tableName, rules: true },
            { ...commonTableList.sortId, rules: true },
            {
                dataIndex: 'attachmentUuid',
                title: '文件附件',
                valueType: 'upload',
                valueFile: [1, 2, 3, 4, 5],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '文件附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
            {
                title: '创建时间',
                dataIndex: 'createTime',
                valueType: 'input',
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 500,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { attachment } = record
                    return [
                        attachment?.fileUrl && (
                            <AnnexButton
                                OptionsEvent={OptionsEvent}
                                key="see"
                                url={attachment.fileUrl}
                                title="附件信息"
                            />
                        ),
                        Permission.findIndex(v => v.uuid === 'f395a7ed-64f2-416e-bbfe-63e1c3ac81fc') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="PlanStatAttachment"
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return dataList
}
